// #123;@123;@345;#1
const useMention = () => {
  const mentionList = ref([])
  const getMentionList = (mentions) => {
    const list = mentions.split(';')
    list.forEach((item) => {
      item = item.trim()
      if (item.startsWith('#')) {
        mentionList.value.push({
          type: 0,
          id: item.slice(1),
          name: 'TODO'
        })
      } else if (item.startsWith('@')) {
        mentionList.value.push({
          type: 1,
          id: item.slice(1),
          name: 'TODO'
        })
      }
    })
  }
  const convertString2TwoLists = (mentions) => {
    // #1;@2;@3;#4 => {research:[1,4],user:[2,3]}
    const list = mentions.split(';')
    const research = []
    const user = []
    list.forEach((item) => {
      item = item.trim()

      if (item.startsWith('#')) {
        research.push(item.slice(1))
      } else if (item.startsWith('@')) {
        user.push(item.slice(1))
      }
    })
    return {
      mentionsResearch: research,
      mentionsUser: user
    }
  }
  return {
    mentionList,
    getMentionList,
    convertString2TwoLists
  }
}
export default useMention
